#include <stdio.h>
#include "nfa.h"

#define UC_A 0x61
#define UC_B 0x62
#define UC_C 0x63

int main(int argc, char** argv)
{
  /* Construct an NFA for the regular expression pattern a+b*.c */

  NFANode a, b, c, split_plus, split_star, dot, term;

  /* Create non-split nodes: */
  r_nfanode_init_char(&a, 1);
  r_nfanode_add_class(&a, R_NFA_CLASS_SINGLE, UC_A, 0);
  r_nfanode_init_char(&b, 1);
  r_nfanode_add_class(&b, R_NFA_CLASS_SINGLE, UC_B, 0);
  r_nfanode_init_char(&c, 1);
  r_nfanode_add_class(&c, R_NFA_CLASS_SINGLE, UC_C, 0);
  r_nfanode_init_char(&dot, 1);
  r_nfanode_add_class(&dot, R_NFA_CLASS_ANY, 0, 0);
  r_nfanode_init_term(&term, 0);

  /* Create split nodes: */
  r_nfanode_init_split(&split_plus, 2);
  r_nfanode_init_split(&split_star, 2);
  r_nfanode_set_next(&a, &split_plus);
  r_nfanode_set_next(&b, &dot);
  r_nfanode_set_next(&dot, &c);
  r_nfanode_set_next(&c, &term);
  r_nfanode_add_child(&split_plus, &a);
  r_nfanode_add_child(&split_plus, &split_star);
  r_nfanode_add_child(&split_star, &b);
  r_nfanode_add_child(&split_star, &dot);

  NFAState state;
  r_nfastate_init(&state);
  r_nfastate_activate(&state, &a);
  uni_char array[] = {UC_A, UC_A, UC_B, UC_A, UC_C, UC_C};
  int i;
  for (i = 0; i < 6; i++){
    r_nfastate_step(&state, array[i]);
    if (r_nfastate_any(&state)) printf("any = yes\n");
    int j;
    for (j = 0; j < r_nfastate_num(&state); j++){
      printf("type = %" PRIu32 ", p = %p\n",
             r_nfastate_active(&state, j)->type,
             r_nfastate_active(&state, j));
    }
  }
  return 0;
}
